package com.danh.game;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.view.animation.TranslateAnimation;

public class DemoGameActivity extends Activity {
	// TODO Image view
	View imgView_Start;
	View imgView_Extra;
	View imgView_Options;
	View txtTicker;
	View imgView_Light;

	// TODO Animation
	Animation mAnimation_Start;
	private View imgView_Menu;
	private View imgView_Menu_2;
	Animation mAnimation_btStart;
	Animation mAnimation_txtTicker;
	Animation mAnimation_Light;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.mainmenu);

		// TODO init image view
		imgView_Start = findViewById(R.id.imgView_Start);
		imgView_Extra = findViewById(R.id.imgView_Extra);
		imgView_Options = findViewById(R.id.imgView_Options);
		imgView_Menu = findViewById(R.id.imgMenu);
		imgView_Menu_2 = findViewById(R.id.imgMenu_2);
		txtTicker = findViewById(R.id.txtTicker);
		if(txtTicker!=null){
			txtTicker.setFocusable(true);
			txtTicker.requestFocus();
			txtTicker.setSelected(true);
		}
		imgView_Light = findViewById(R.id.imgLight);

		// TODO load animation for image view
		mAnimation_Start = AnimationUtils.loadAnimation(this, R.anim.slide);
		mAnimation_btStart = AnimationUtils.loadAnimation(this, R.anim.flicker);
		mAnimation_txtTicker = AnimationUtils.loadAnimation(this, R.anim.fadein);
		mAnimation_Light = AnimationUtils.loadAnimation(this, R.anim.light);
	}

	private View.OnClickListener onClickButton_Start = new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			v.startAnimation(mAnimation_btStart);
		}
	};

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();

		if (imgView_Start != null) {
			imgView_Start.setOnClickListener(onClickButton_Start);
		}

		if (imgView_Start != null) {
			AlphaAnimation mAnimation = new AlphaAnimation(0f, 1f);
			mAnimation.setDuration(1000);
			mAnimation.setStartOffset(500L);
			imgView_Start.startAnimation(mAnimation);
		}
		if (imgView_Extra != null) {
			// Animation anim = mAnimation_Start;
			// anim.setStartOffset(500L);

			AlphaAnimation mAnimation = new AlphaAnimation(0f, 1f);
			mAnimation.setDuration(1000);
			mAnimation.setStartOffset(1500L);
			imgView_Extra.startAnimation(mAnimation);
		}
		if (imgView_Options != null) {
			// Animation anim = mAnimation_Start;
			// anim.setStartOffset(1000L);

			AlphaAnimation mAnimation = new AlphaAnimation(0f, 1f);
			mAnimation.setDuration(1000);
			mAnimation.setStartOffset(2500L);

			// TranslateAnimation mTranslate = new TranslateAnimation(0, 500,
			// 0,-300);
			// mTranslate.setFillAfter(true);
			// mTranslate.setDuration(4000);
			// mTranslate.setStartOffset(2500L);
			//
			mAnimation.setAnimationListener(new AnimationListener() {

				@Override
				public void onAnimationStart(Animation animation) {
					// TODO Auto-generated method stub

				}

				@Override
				public void onAnimationRepeat(Animation animation) {
					// TODO Auto-generated method stub

				}

				@Override
				public void onAnimationEnd(Animation animation) {
					// TODO Auto-generated method stub
					TranslateAnimation mTranslate = new TranslateAnimation(100,
							0, 0, 0);
					mTranslate.setFillBefore(true);
					mTranslate.setDuration(500);
					mTranslate.setRepeatCount(5);
					// mTranslate.setStartOffset(2500L);

					mTranslate.setAnimationListener(new AnimationListener() {

						@Override
						public void onAnimationStart(Animation animation) {
							// TODO Auto-generated method stub

						}

						@Override
						public void onAnimationRepeat(Animation animation) {
							// TODO Auto-generated method stub

						}

						@Override
						public void onAnimationEnd(Animation animation) {
							// TODO Auto-generated method stub
							TranslateAnimation mTranslate1 = new TranslateAnimation(
									100, 0, 0, 0);
							mTranslate1.setFillAfter(true);
							mTranslate1.setDuration(500);
							imgView_Menu_2.setVisibility(View.VISIBLE);
							imgView_Menu_2.setAnimation(mTranslate1);
						}
					});

					imgView_Menu.setVisibility(View.VISIBLE);
					imgView_Menu.setAnimation(mTranslate);
				}
			});
			imgView_Options.startAnimation(mAnimation);

		}
		
		//TODO animation for textview
		if(txtTicker!=null){
			txtTicker.clearAnimation();
			txtTicker.startAnimation(mAnimation_txtTicker);
		}

		if(imgView_Light!=null)
			imgView_Light.startAnimation(mAnimation_Light);
	}
}